/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package lineage.core.handler;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Queue;

import lineage.core.L1GameClient;
import lineage.core.encryptions.Encryption;

/**
 * 处理器的抽象类.
 * 
 * @version 2014年3月9日下午2:51:21
 * @author jrwz
 */
public abstract class L1AbstractHandler {
    /** 客户端. */
    protected L1GameClient client;
    /** 输入流. */
    protected InputStream in;
    /** 输出流. */
    protected OutputStream out;
    /** 密钥. */
    protected Encryption keys;
    /** 封包输入管理. */
    protected L1PacketAcceptHandler pah;
    /** 封包输出管理. */
    protected L1PacketSendHandler psh;
    /** 队列. */
    protected Queue<byte[]> queue;

    /**
     * 开始解密.
     * 
     * @return 解密后的byte数组
     * @throws Exception
     */
    protected byte[] toDecrypt() throws Exception {
        return null;
    }

    /**
     * 开始加密.
     * 
     * @param data
     *            - 要加密的数据
     * @return 加密后的byte数组
     * @throws Exception
     */
    protected byte[] toEncrypt(final byte[] data) throws Exception {
        return null;
    }

    /**
     * 开始处理.
     * 
     * @param data
     *            - 要处理的数据
     */
    protected void execute(final byte[] data) {
    }

    /**
     * 加入工作队列(稍后处理).
     * 
     * @param data
     *            - 要处理的数据
     */
    protected void executeQueue(final byte[] data) {
    }

    /**
     * 关闭流.
     */
    protected abstract void close();

    /**
     * 取得客户端.
     * 
     * @return 客户端对象
     */
    public L1GameClient getClient() {
        return client;
    }

    /**
     * 取得输入流.
     * 
     * @return 输入流
     */
    public InputStream getIn() {
        return in;
    }

    /**
     * 取得输出流.
     * 
     * @return 输出流
     */
    public OutputStream getOut() {
        return out;
    }

    /**
     * 取得密钥.
     * 
     * @return 密钥
     */
    public Encryption getKeys() {
        return keys;
    }
}
